package com.yanyilu.basing.controller;


import com.yanyilu.basing.common.R;
import com.yanyilu.basing.entity.CheckInRecord;
import com.yanyilu.basing.jwt.JwtIgnore;
import com.yanyilu.basing.service.ICheckInRecordService;
import com.yanyilu.basing.util.ParseJwtUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author Sxx
 * @since 2020-10-26
 */
@CrossOrigin
@RestController
@RequestMapping("/checkinrecord")
public class CheckInRecordController {
    @Autowired
    ICheckInRecordService checkInRecordService;

    /**
     * 用户打卡记录列表
     * @param limit
     * @param page
     * @return
     */
    @GetMapping("/frontend/list")
    public R getList(@RequestParam("limit") Integer limit,@RequestParam("page")Integer page){
        Integer userId = ParseJwtUtil.getUserId();
        return checkInRecordService.getRecordList(userId,limit,page);
    }

    /**
     * 添加打卡记录
     * @param checkInRecord
     * @return
     */
    @PostMapping("/frontend/add")
    public R addRecord(@RequestBody CheckInRecord checkInRecord){
        Integer userId = ParseJwtUtil.getUserId();
        checkInRecord.setUserId(userId);
        return checkInRecordService.addCheckInRecord(checkInRecord);
    }

    /**
     * 用户打卡记录列表(管理端)
     * @param limit
     * @param page
     * @return
     */
    @RequestMapping("/admin/list")
    public R adminGetList(@RequestParam("limit") Integer limit,@RequestParam("page")Integer page,
                          @RequestParam(value = "reviewState",required = false)Integer reviewState){

        return checkInRecordService.getAdminRecordList(reviewState,limit,page);
    }

    /**
     * 审核
     * @param checkInRecord
     * @return
     */
    @RequestMapping("/admin/review")
    public R adminUpdate(@RequestBody CheckInRecord checkInRecord){
        checkInRecordService.adminUpdate(checkInRecord);
        return R.ok();
    }
}
